package com.jason.www.dao;

import com.jason.www.domain.OrderDetail;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface OrderDetailMapper {

    @Delete({
        "delete from order_detail",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into order_detail (id, orders_id, ",
        "items_id, items_num)",
        "values (#{id,jdbcType=BIGINT}, #{ordersId,jdbcType=BIGINT}, ",
        "#{itemsId,jdbcType=BIGINT}, #{itemsNum,jdbcType=INTEGER})"
    })
    int insert(OrderDetail record);

    @InsertProvider(type=OrderDetailSqlProvider.class, method="insertSelective")
    int insertSelective(OrderDetail record);

    @Select({
        "select",
        "id, orders_id, items_id, items_num",
        "from order_detail",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @Results(id="orderDetailMap",value = {
            @Result(column="id", property="id", jdbcType=JdbcType.BIGINT, id=true),
            @Result(column="orders_id", property="ordersId", jdbcType=JdbcType.BIGINT),
            @Result(column="items_id", property="itemsId", jdbcType=JdbcType.BIGINT),
            @Result(column="items_num", property="itemsNum", jdbcType=JdbcType.INTEGER)
    })
    OrderDetail selectByPrimaryKey(Long id);

    @Select({
            "select",
            "id, orders_id, items_id, items_num",
            "from order_detail",
            "where orders_id = #{ordersId}"
    })
    @ResultMap("orderDetailMap")
    List<OrderDetail> selectByOrdersId(Long ordersId);

    @UpdateProvider(type=OrderDetailSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderDetail record);

    @Update({
        "update order_detail",
        "set orders_id = #{ordersId,jdbcType=BIGINT},",
          "items_id = #{itemsId,jdbcType=BIGINT},",
          "items_num = #{itemsNum,jdbcType=INTEGER}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(OrderDetail record);
}